import {
    UserProfilesAPI
} from '@/request/api'
export default {
    namespaced: true,
    state: {
        //用户信息
        userInfo: {
            //昵称
            nickName: '',
            coin: 0,
            headImg: require('../../assets/img/service.848ec511.png'),
        },
        //购物车数量
        cartTotal: 8
    },
    mutations: {
        //修改登录状态
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        //初始化仓库属性的
        initUserInfo(state) {
            state.userInfo = {
                //昵称
                nickName: '',
                coin: 0,
                headImg: require('../../assets/img/service.848ec511.png'),
            }
            state.cartTotal = 8;
        }
    },
    actions: {
        //请求用户信息
        async asyncchangeUserInfo({
            commit
        }) {
            //1.请求用户信息
            let user = await UserProfilesAPI();
            // console.log("用户信息", user);
            //2.更新vuex中用户信息 调用mutations
            commit("changeUserInfo", user.data)
        }
    }
}